package com.example.notificationtest;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.widget.Button;

import java.io.File;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn = (Button) findViewById(R.id.btn);
        Button btn2 = (Button) findViewById(R.id.btn2);
        btn.setOnClickListener(this);
        btn2.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn:
                Intent intent = new Intent(this, NotificationActivity.class);
                PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); // 通知的意图封装

                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Notification notification = new NotificationCompat.Builder(this)
                        .setContentTitle("我是标题")
                        .setContentText("我是通知的内容")
                        .setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setContentIntent(pi)  // 意图跳转
                        .setAutoCancel(true)  // 点击后从通知栏消失
                        .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg")))    // 设置音乐
                        .setVibrate(new long[]{0, 5000, 1000, 1000,})  // 手机震动  简写0毫秒开始震10S 间歇1S 震1S
                        .setLights(Color.WHITE, 2000, 1000) // 控制灯的闪烁
                        .setPriority(NotificationCompat.PRIORITY_MAX)   // 通知优先级
                        .build();
                manager.notify(1, notification);
                break;
            case R.id.btn2:
                intent = new Intent(this, NotificationActivity.class);
                pi = PendingIntent.getActivity(this, 0, intent, 0); // 通知的意图封装

                manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notification = new NotificationCompat.Builder(this)
                        .setContentTitle("我是标题")
                        .setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setContentIntent(pi)  // 意图跳转
                        .setAutoCancel(true)  // 点击后从通知栏消失
                        .setDefaults(NotificationCompat.DEFAULT_ALL)   // 设置通知时手机默认环境通知
                        .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.a1)))  // 设置通知栏大图
//                        .setStyle(new NotificationCompat.BigTextStyle().bigText("ljaklsjdfjwqioejf;asslkddddkljfklsjfdlkjalskdjfakljsdfkljsdlkjfiowq" +
//                                "ljwqjefiojqwdiofjqoiwjefoiqjweoifjq;ojefoiqjfkdfijqwioefjqiwefjojqw群文件覅偶去我甲额覅偶奇我就问父亲我"))   // 设置长文本
                        .setPriority(NotificationCompat.PRIORITY_MAX)   // 通知优先级
                        .build();
                manager.notify(2, notification); //
                break;
            default:
                break;
        }


    }

}
